package com.ruoyi.funding.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.funding.mapper.FundingExpenditureMapper;
import com.ruoyi.funding.domain.FundingExpenditure;
import com.ruoyi.funding.service.IFundingExpenditureService;

import static com.ruoyi.common.security.utils.SecurityUtils.getUsername;

/**
 * 资金支出记录 Service业务层处理
 * 
 * @author ycl
 * @date 2025-01-06
 */
@Service
public class FundingExpenditureServiceImpl implements IFundingExpenditureService 
{
    @Autowired
    private FundingExpenditureMapper fundingExpenditureMapper;

    /**
     * 查询资金支出记录 
     * 
     * @param expenditureId 资金支出记录 主键
     * @return 资金支出记录 
     */
    @Override
    public FundingExpenditure selectFundingExpenditureByExpenditureId(Long expenditureId)
    {
        return fundingExpenditureMapper.selectFundingExpenditureByExpenditureId(expenditureId);
    }

    /**
     * 查询资金支出记录 列表
     * 
     * @param fundingExpenditure 资金支出记录 
     * @return 资金支出记录 
     */
    @Override
    public List<FundingExpenditure> selectFundingExpenditureList(FundingExpenditure fundingExpenditure)
    {
        return fundingExpenditureMapper.selectFundingExpenditureList(fundingExpenditure);
    }

    /**
     * 新增资金支出记录 
     * 
     * @param fundingExpenditure 资金支出记录 
     * @return 结果
     */
    @Override
    public int insertFundingExpenditure(FundingExpenditure fundingExpenditure)
    {
        fundingExpenditure.setCreateTime(DateUtils.getNowDate());
        fundingExpenditure.setCreateBy(getUsername());
        return fundingExpenditureMapper.insertFundingExpenditure(fundingExpenditure);
    }

    /**
     * 修改资金支出记录 
     * 
     * @param fundingExpenditure 资金支出记录 
     * @return 结果
     */
    @Override
    public int updateFundingExpenditure(FundingExpenditure fundingExpenditure)
    {
        fundingExpenditure.setUpdateTime(DateUtils.getNowDate());
        fundingExpenditure.setUpdateBy(getUsername());
        return fundingExpenditureMapper.updateFundingExpenditure(fundingExpenditure);
    }

    /**
     * 批量删除资金支出记录 
     * 
     * @param expenditureIds 需要删除的资金支出记录 主键
     * @return 结果
     */
    @Override
    public int deleteFundingExpenditureByExpenditureIds(Long[] expenditureIds)
    {
        for (Long expenditureId : expenditureIds) {
            FundingExpenditure fundingExpenditure = fundingExpenditureMapper.selectFundingExpenditureByExpenditureId(expenditureId);
            fundingExpenditure.setDeleteBy(getUsername());
            fundingExpenditure.setDeleteTime(new Date());
            fundingExpenditureMapper.updateFundingExpenditure(fundingExpenditure);
        }

        return fundingExpenditureMapper.deleteFundingExpenditureByExpenditureIds(expenditureIds);
    }

    /**
     * 删除资金支出记录 信息
     * 
     * @param expenditureId 资金支出记录 主键
     * @return 结果
     */
    @Override
    public int deleteFundingExpenditureByExpenditureId(Long expenditureId)
    {
        FundingExpenditure fundingExpenditure = fundingExpenditureMapper.selectFundingExpenditureByExpenditureId(expenditureId);
        fundingExpenditure.setDeleteBy(getUsername());
        fundingExpenditure.setDeleteTime(new Date());
        fundingExpenditureMapper.updateFundingExpenditure(fundingExpenditure);

        return fundingExpenditureMapper.deleteFundingExpenditureByExpenditureId(expenditureId);
    }
}
